package com.lsh.oms.core.model.order;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lsh.base.lang.json.Jsons;
import com.lsh.oms.core.model.calService.CalShippingHeadVo;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Map;

/**
 * @author peter
 */
@Setter
@Getter
@NoArgsConstructor
public class OrderShippingHeadWithBLOBs extends OrderShippingHead implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = -8966894299618327814L;

    private String ext;

    private String warehouseData;

    private String marketName;

    private String addressTelephone;

    private Map<String, Object> extendedProperties;

    private Map<String, Object> warehouseInfo;

    public Map<String, Object> getExtendedProperties() {
        if (extendedProperties == null && StringUtils.isNotBlank(ext)) {
            extendedProperties = Jsons.fromJsonString(ext);
        }
        return extendedProperties;
    }

    public Map<String, Object> getWarehouseInfo() {
        if (warehouseInfo == null && StringUtils.isNotBlank(warehouseData)) {
            warehouseInfo = Jsons.fromJsonString(warehouseData);
        }
        return warehouseInfo;
    }

    public JSONObject addressProperties() {
        String address = this.getAddressInfo();
        if (StringUtils.isNotBlank(address)) {

            return JSON.parseObject(this.getAddressInfo());
        }

        return new JSONObject();
    }


    public OrderShippingHeadWithBLOBs(CalShippingHeadVo vo) {
        this.setSkuCount(new BigDecimal(vo.getSku_count()));
        this.setRealSkuCount(vo.getReal_sku_count());
        this.setMoney(new BigDecimal(vo.getMoney()));
        this.setFloorMoney(new BigDecimal(vo.getFloor_money()));
        this.setCouponMoney(new BigDecimal(vo.getCash_coupon_money()));
        this.setActivedAt(vo.getActived_at());
        this.setShippedAt(vo.getShipped_at());
        this.setTmsId(0L);
        this.setTransUid(0L);
        this.setWaybillNo("");
        //初始化4
        this.setReceiptStatus(4);
        this.setDelayType(0);
        this.setZoneId(Integer.parseInt(vo.getZone_id()));
        this.setStorageTypeId(2);
        this.setTmsId(0L);
        this.setOrderFrom(1);
        this.setCarType("");
        this.setTurnoverboxNum(0);
        this.setBoxNum(0);
        this.setSeq(0);
        this.setIsPrecedence(1);
        this.setIsValid(1);
        this.setOmsExt("");
        this.setExt("");
        this.setWarehouseData("");
        this.setMarketName("");
        this.setAddressTelephone("");
    }


}